package br.com.fiap.DAO;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Connection;
import br.com.fiap.ConnectionFactory.ConnectionFactory;
import br.com.fiap.bean.AcessoConta;
import br.com.fiap.bean.Conta;

public class AcessoContaDAO {
	public AcessoConta getUnique(Conta conta) throws SQLException, ClassNotFoundException{
		
		AcessoConta acessoConta = new AcessoConta();
		
		Connection conn = ConnectionFactory.getConnection();
		
		String sql = "SELECT * FROM BANCO.ACESSO WHERE conta = ? and contaagencia = ? and contatipo = ? and contabanco = ?";
		
		PreparedStatement stmt = conn.prepareStatement(sql);
		stmt.setInt(1, conta.getNumero());
		stmt.setInt(2, conta.getAgencia().getNumero());
		stmt.setInt(3, conta.getTipo());
		stmt.setInt(4, conta.getAgencia().getBanco().getNumero());
		
		ResultSet rs = stmt.executeQuery();
		
		if(rs.next()){
			acessoConta.setSenhaelet(rs.getString("senhaelet"));
			acessoConta.setSenhacart(rs.getString("senhacart"));	
		}

		conn.close();
		
		return acessoConta;
	}
}
